CallGraph
uicallgraphpanel.cpp
Go to the documentation of this file.
00001 #include "uicallgraphpanel.h"
00002 #include "workspace.h"
00003 #include <wx/dcbuffer.h>
00004 #include <wx/bitmap.h>
00005 #include <wx/filedlg.h>
00006 #include <wx/filefn.h>
00007 #include <wx/xrc/xmlres.h> 
00008 
00009 uicallgraphpanel::uicallgraphpanel(wxWindow *parent, IManager *mgr, const wxString& imagepath, LineParserList *pLines) : uicallgraph(parent)
00010 {
00011         m_mgr = mgr;
00012         pathimage = imagepath;
00013         mlines = pLines;
00014         
00015         m_Bmp.LoadFile(pathimage, wxBITMAP_TYPE_PNG);
00016         int x = m_Bmp.GetWidth() + 30;
00017         int y = m_Bmp.GetHeight() + 30;
00018         
00019         m_scrolledWindow->SetBackgroundColour(wxColour(255, 255, 255));
00020         m_scrolledWindow->SetBackgroundStyle(wxBG_STYLE_CUSTOM);
00021         m_scrolledWindow->SetVirtualSize(x, y);
00022         
00023         // inizialise and create table for insert data from LineParserList
00024         m_mgr->GetConfigTool()->ReadObject(wxT("CallGraph"), &confData);
00025         CreateAndInserDataToTable();
00026         
00027 }
00028 
00029 uicallgraphpanel::~uicallgraphpanel()
00030 {
00031 }
00032 
00033 void uicallgraphpanel::OnPaint(wxPaintEvent& event)
00034 {
00035         wxRect rectUpdate = m_scrolledWindow->GetUpdateRegion().GetBox();
00036         wxPoint ptVirt = m_scrolledWindow->CalcUnscrolledPosition(rectUpdate.GetTopLeft());
00037         // move from origin
00038         ptVirt.x -= 20;
00039         ptVirt.y -= 20;
00040                 
00041         wxAutoBufferedPaintDC dc(m_scrolledWindow);
00042         wxMemoryDC memDC(m_Bmp);
00043         
00044         dc.SetBrush( wxBrush( m_scrolledWindow->GetBackgroundColour() ) );
00045         dc.Clear();
00046         dc.Blit(rectUpdate.GetTopLeft(), rectUpdate.GetSize(), &memDC, ptVirt, wxCOPY);
00047 }
00048 
00049 void uicallgraphpanel::OnSaveCallGraph(wxCommandEvent& event)
00050 {       
00051                 //wxString projectName = m_mgr->GetWorkspace()->GetActiveProjectName();
00052 
00053                 wxFileDialog saveFileDialog(this, _("Save call graph..."), _(""), wxT("CallGraph"), _("png files (*.png)|*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
00054 
00055         if (saveFileDialog.ShowModal() == wxID_CANCEL)
00056             return;
00057                 
00058                 m_Bmp.SaveFile(saveFileDialog.GetPath(), wxBITMAP_TYPE_PNG);
00059 }
00060 
00061 void uicallgraphpanel::OnClosePanel(wxCommandEvent& event)
00062 {
00063         wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, XRCID("close_file"));
00064         m_mgr->GetTheApp()->GetTopWindow()->GetEventHandler()->AddPendingEvent(evt);
00065 }
00066 
00067 /*
00068 void uicallgraphpanel::NumberOfPrimaryLinesAndSize()
00069 {
00070         row_label_size = 0;
00071         rows = 0;
00072         LineParserList::compatibility_iterator it = mlines->GetFirst();
00073         
00074         while(it)
00075         {
00076                 LineParser *line = it->GetData();
00077                 
00078                 if(line->pline)
00079                 {
00080                         int rls = line->name.Len();
00081                         if (rls > row_label_size) row_label_size = rls;
00082                         rows ++;                        
00083                 }
00084                 
00085                 it = it->GetNext();
00086         }
00087         row_label_size = row_label_size + 10;
00088         rows = rows + 1;
00089 }*/
00090 
00091 void uicallgraphpanel::CreateAndInserDataToTable()
00092 {
00093         LineParserList::compatibility_iterator it = mlines->GetFirst();
00094         int nr = 0;
00095         while(it)
00096         {
00097                 LineParser *line = it->GetData();
00098                 if(line->pline && wxRound(line->time) >= confData.GetTresholdNode())
00099                 {
00100                         //int rls = line->name.Len();
00101                         //if (rls > row_label_size) row_label_size = rls;
00102                         //
00103                         m_grid->AppendRows(1, true);
00104                         //name   time %   self  children    called
00105                         m_grid->SetCellValue(nr, 0, line->name);
00106                         m_grid->SetCellValue(nr, 1, wxString::Format(wxT("%.2f"),line->time));
00107                         m_grid->SetCellValue(nr, 2, wxString::Format(wxT("%.2f"),line->self));
00108                         //m_grid->SetCellValue(nr, 3, wxString::Format(wxT("%.2f"),line->childern));
00109                         //
00110                         int callsum;
00111                         if(line->called0 != -1) 
00112                         {
00113                                 callsum = line->called0;
00114                                 if(line->called1 != -1) callsum += line->called1;
00115                         }
00116                         else callsum = 1;
00117                         //
00118                         m_grid->SetCellValue(nr, 3, wxString::Format(wxT("%i"),callsum));
00119                         nr ++;
00120                 }
00121                 it = it->GetNext();
00122         }
00123         
00124         m_grid->AutoSize();
00125         m_grid->Fit();
00126 }
 All Classes Files Functions Variables